package com.xigua.chapter_1_iterator.example_1_1.book;

import java.util.ArrayList;

/**
 * @author LiRongHua
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2022/3/2616:48
 */
public class BookShelf implements Aggreate {
    private ArrayList<Book> books;
    private int last =0;

    public BookShelf(int maxSize) {
        this.books = new ArrayList<Book>(maxSize);
    }

    public Book getBookAt(int index){
        return books.get(index);
    }

    public void appendBook(Book book){
        books.add(book);
        last++;
    }

    public int getLength(){
        return last;
    }


    public Iterator iterator() {
        return new BookShelfIterator(this);
    }
}
